package cn.cjp.m3d26;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;

public class fIterator {
    public static void main(String[] args) {
        Collection coll = new ArrayList();
        coll.add("aaa");
        coll.add("bbb");
        coll.add("ccc");
        coll.add("ddd");

        //通过集合的方法获取迭代器的实现类对象（多态）
        //集合是什么泛型，迭代器就是什么泛型
        Iterator<String> it =  coll.iterator();

        //判断还有没有下个元素
        boolean b = it.hasNext();
        System.out.println(b);
        //取出下一元素
        String str = it.next();
        System.out.println(str);
        System.out.println("=================");

        b = it.hasNext();
        str = it.next();
        System.out.println(b);
        System.out.println(str);
        System.out.println("=================");

        b = it.hasNext();
        str = it.next();
        System.out.println(b);
        System.out.println(str);
        System.out.println("=================");

        b = it.hasNext();
        str = it.next();
        System.out.println(b);
        System.out.println(str);
        System.out.println("=================");

        System.out.println(it.hasNext()+"此时集合空了");
        System.out.println("=================");

        Iterator<String> it1 =  coll.iterator();
        while(it1.hasNext()){
            System.out.println(it1.next());
        }
    }
}
